<?php
namespace app\zbj\controller;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

class Editpwd extends Base
{
    public function index()
    {
        return view('editpwd/index');
    }

    public function edit(){
        $param = myarr($this->request->post());

        if($param['newpassword']!=$param['newpassword2']) return "<script>alert('两次密码不一致');history.go(-1)</script>";
        $vip = Db::name('admin_user')->where('id',session('zbjUser.id'))->find();
        if(Md5('lc'.$param['oldpassword'])!=$vip['userpass']) return "<script>alert('旧密码验证失败');history.go(-1)</script>";

        $up = Db::name('admin_user')->where('id',$vip['id'])->update(['userpass'=>Md5('lc'.$param['newpassword'])]);
        if($up) echo "<script>alert('修改成功，请重新登录');parent.location.reload();</script>";
        Session(null);

    }
}
